﻿
using Sumen.Library.Enum;
using Sumen.Library.Interface;
using Sumen.Model.Model;

namespace Sumen.Business
{
    public class PermissionActual : IPermission
    {
        private int permissionAll;


        public sys_object SysObject { get; set; }
        //public int? PermissionAll
        //{
        //    get
        //    {
                
        //    }
        //    set
        //    {
        //        permissionAll = value;
        //        View = PermissionView();
        //        Add = PermissionAdd();
        //        Update = PermissionUpdate();
        //        Delete = PermissionDelete();
        //        Print = PermissionPrint();
        //        Word = PermissionWord();
        //        Excel = PermissionExcel();
        //        Report = PermissionReport();
        //        Approved = PermissionApproved();
        //    }
        //}

        public bool View { get; set; }
        public bool Add { get; set; }
        public bool Update { get; set; }
        public bool Delete { get; set; }
        public bool Print { get; set; }
        public bool Word { get; set; }
        public bool Excel { get; set; }
        public bool Report { get; set; }
        public bool Approved { get; set; }

        protected bool getPermission(EnumFormStatus pEnumFormStatus)
        {
            if (permissionAll == null)
            {
                return false;
            }
            else
            {
                return (permissionAll & (int)pEnumFormStatus) != 0;
            }
        }


        public bool PermissionView()
        {
            return getPermission(EnumFormStatus.View);
        }

        public bool PermissionAdd()
        {
            return getPermission(EnumFormStatus.Add);
        }

        public bool PermissionUpdate()
        {
            return getPermission(EnumFormStatus.Modify);
        }

        public bool PermissionDelete()
        {
            return getPermission(EnumFormStatus.Delete);
        }

        public bool PermissionPrint()
        {
            return getPermission(EnumFormStatus.Print);
        }

        public bool PermissionWord()
        {
            return getPermission(EnumFormStatus.Word);
        }

        public bool PermissionExcel()
        {
            return getPermission(EnumFormStatus.Excel);
        }

        public bool PermissionApproved()
        {
            return getPermission(EnumFormStatus.Approved);
        }

        public bool PermissionReport()
        {
            return getPermission(EnumFormStatus.Report);
        }





       public int PermissionAll()
        {
            permissionAll = 0;
            permissionAll += View ? (int)EnumFormStatus.View : 0;
            permissionAll += Add ? (int)EnumFormStatus.Add : 0;
            permissionAll += Update ? (int)EnumFormStatus.Modify : 0;
            permissionAll += Delete ? (int)EnumFormStatus.Delete : 0;
            permissionAll += Print ? (int)EnumFormStatus.Print : 0;
            permissionAll += Word ? (int)EnumFormStatus.Word : 0;
            permissionAll += Excel ? (int)EnumFormStatus.Excel : 0;
            permissionAll += Report ? (int)EnumFormStatus.Report : 0;
            permissionAll += Approved ? (int)EnumFormStatus.Approved : 0;
            return permissionAll;
        }
    }
}
